//将请求回来的数据添加到vuex中
import {reqSearchGoodsInfo} from '../../api'

const state ={
    goodsInfo:{}
}

const actions = {
     async getSearchGoodsInfo({commit},searchParams){
         //console.log('actions收到数据');
        const result = await reqSearchGoodsInfo(searchParams)
        if(result.code === 200){
             commit('SAVE_SEARCH_INFO',result.data)
        }else{
             console.log(result.message);
        }
     }
}

const  mutations = {
    SAVE_SEARCH_INFO(state,payload){
        //console.log('mutations收到数据');
        state.goodsInfo = payload
    }
}

const getters = {
    //售卖属性（尺寸，像素，价格这一类）
    attrsList(state){
        return state.goodsInfo.attrsList
    },
    //10个手机图片
    goodsList(state){
        return state.goodsInfo.goodsList
    },
    //品牌单选：小米、苹果、华为
    trademarkList(state){
        return state.goodsInfo.trademarkList
    },
    //显示页码的
    total(state){
          return state.goodsInfo.total
    }
}

export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}